var PlayMainLayer = cc.Layer.extend({
	desk:null,
	computer_open:null,
	computer_close:null,
	uv1800:null,
	flow:null,
	scene:null,
	equit:null,
	vessel:null,
	vessel1:null,
	status:true,
	ctor:function(parent,tag) {
		this._super();
		this.init();
		this.scene=parent;
		this.setTag(tag);
		this.flow=this.scene.flow;
		this.scene.addChild(this,10,TAG_MAIN);
//		this.fadeinLabel();
		this.showTip=new ShowTip(this,"洗涤玻璃仪器,连接和检查仪器",cc.p(gg.c_width, gg.c_height*1.5));
		this.loadEquitment();
	},
	loadEquitment:function(){
		this.comp = new Comp(this,this.flow,TAG_UV_OPENPC);
		this.uv=new Uv(this,this.flow,TAG_UV_OPENUV);
		this.equitment=new Equitment(this,this.flow,TAG_UV_EQUITMENT);
		this.sample=new Sample(this,this.flow,TAG_UV_SAMPLE);
		this.equitment1=new Equitment1(this,this.flow,TAG_UV_EQUITMENT1);
		
		var fontDef = new cc.FontDefinition();
		fontDef.fontName = "Arial";
		fontDef.fontSize = "20";
		fontDef.fillStyle=cc.color(0, 0, 0,255);
//		// 擦镜纸
		this.paperItem=new Button(this,11,TAG_ITEM_PAPERITEM,
				"#button/paper_item.png",this.eventMenuCallback);
		this.paperItem.setPosition(gg.width*0.88,gg.height*0.945);
		this.paper=new Button(this,10,TAG_PAPER,"#xishuizhi1.png",this.eventMenuCallback);
		this.paper.setPosition(gg.width*0.88,gg.height*0.945);
		this.paper.setVisible(false);
		var label1=new cc.LabelTTF("擦镜纸",fontDef);
		label1.setPosition(cc.p(gg.width*0.88,gg.height*0.88));
		this.addChild(label1);
		// 吸水纸
		this.paperItem1=new Button(this,11,TAG_ITEM_PAPERITEM1,
				"#button/paper_item1.png",this.eventMenuCallback);
		this.paperItem1.setPosition(gg.width*0.80,gg.height*0.945);
		this.paper1=new Button(this,10,TAG_PAPER1,"#xishuizhi1.png",this.eventMenuCallback);
		this.paper1.setPosition(gg.width*0.80,gg.height*0.945);
		this.paper1.setVisible(false);
		var label2=new cc.LabelTTF("吸水纸",fontDef);
		label2.setPosition(cc.p(gg.width*0.80,gg.height*0.88));
		this.addChild(label2);
		
		this.desk=new Button(this,1,TAG_ITEM_DESK,
				"#equitment/desk.png",this.eventMenuCallback);
		this.desk.setPosition(gg.c_width*0.9,gg.c_height*0.5);
		
		this.computer_close=new Button(this,2,TAG_ITEM_COMPUTER_CLOSE,
				"#equitment/computer_close.png",this.eventMenuCallback);
		this.computer_close.setPosition(gg.c_width*0.4,gg.c_height*1.08);
		this.computer_close.setVisible(true);

		this.computer_open=new Button(this,2,TAG_ITEM_COMPUTER_OPEN,
				"#equitment/computer_open.png",this.eventMenuCallback);
		this.computer_open.setPosition(gg.c_width*0.4,gg.c_height*1.08);
		this.computer_open.setVisible(false);
		
		this.uv1800=new Button(this,2,TAG_ITEM_UV1800,
				"#equitment/UV1800_a.png",this.eventMenuCallback);
		this.uv1800.setPosition(gg.c_width*0.83, gg.c_height*0.98);
		this.uv1800.setVisible(true);
		
		this.equit=new Button(this,2,TAG_ITEM_EQUIT,
				"#equitment/equit.png",this.eventMenuCallback);
		this.equit.setPosition(gg.c_width*1.25,gg.c_height+5);
	
		this.vessel=new Button(this,2,TAG_ITEM_VESSEL1,
				"#equitment/vessel1.png",this.eventMenuCallback);
		this.vessel.setPosition(gg.c_width*1.2,gg.c_height*0.92);
		this.vessel.setVisible(false);

		this.vessel1=new Button(this,2,TAG_ITEM_VESSEL2,
				"#equitment/vessel1.png",this.eventMenuCallback);
		this.vessel1.setPosition(gg.c_width*1.3,gg.c_height*0.92);
		this.vessel1.setVisible(false);

	},
	showDesc:function(tag){
		if(cur_tool == TAG_BUTTON_HELP){
			for(var i = 0; i< sprite_json.length; i++){
				if(sprite_json[i].tag == tag){
					ll.tip_layer.sayFlash(sprite_json[i].desc);
					cc.log(sprite_json[i].desc);
					break;
				}
			}
		}
	},
	eventMenuCallback:function(pSender){
		this.showDesc(pSender.getTag());
		if(cur_tool != TAG_BUTTON_HAND){
			// 描述
			return;
		}
		if(!this.flow.checkTag(pSender.getTag())){
			// 是否可以触发
			_.error();
			ll.tip_layer.updateScore(gg.score);
			return;
		} else {
			if(this.status==true){
				_.clever();
				ll.tip_layer.updateScore(gg.score);
			}
		}
		var func=cc.callFunc(this.checkActionDone, this);
		var func1=cc.callFunc(function() {
			this.flow.next();
			this.status=true;
		},this);
		var action = this.flow.flow.action;
			switch (pSender.getTag()) {
			case TAG_ITEM_COMPUTER_CLOSE:
				cc.log("点击了电脑");
				if(this.status==true){
					this.status=false;
					pSender.runAction(cc.sequence(cc.callFunc(function() {
						this.comp.open();
					},this),cc.delayTime(0.5),func1));
				}
				break;
			case TAG_ITEM_COMPUTER_OPEN:
				cc.log("点击了打开的电脑");
				if(this.status==true){
					this.status=false;
					if(action==ACTION_DO1){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.comp.open();
							this.comp.button7.setVisible(true);
						}, this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO2){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.comp.open();
							this.comp.bg.setSpriteFrame("software_button/software2.png");
							this.comp.button7.setVisible(true);
							this.comp.button8.setVisible(false);
						},this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO3){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.comp.open();
							this.comp.bg.setSpriteFrame("software_button/software4.png");
							this.comp.button8.setVisible(false);
							this.comp.button9.setVisible(true);
						},this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO4){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.comp.open();
							this.comp.bg.setSpriteFrame("software_button/software8.png");
						},this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO5){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.comp.open();
							this.comp.bg.setSpriteFrame("software_button/software7-1.png");
							this.comp.button7.setVisible(true);
						},this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO6){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.comp.open();
							this.comp.bg.setSpriteFrame("software_button/software7-2.png");
							this.comp.button7.setVisible(true);
						},this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO7){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.comp.open();
							this.comp.bg.setSpriteFrame("software_button/software7-3.png");
							this.comp.button7.setVisible(true);
						},this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO8){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.comp.open();
							this.comp.bg.setSpriteFrame("software_button/software7-4.png");
							this.comp.button7.setVisible(true);
						},this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO9){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.comp.open();
							this.comp.bg.setSpriteFrame("software_button/software7-5.png");
							this.comp.button7.setVisible(true);
						},this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO10){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.comp.open();
							this.comp.bg.setSpriteFrame("software_button/software7-6.png");
							this.comp.button7.setVisible(true);
						},this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO11){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.comp.open();
							this.comp.bg.setSpriteFrame("software_button/software7-7.png");
							this.comp.button7.setVisible(true);
						},this),cc.delayTime(0.5),func1));
					}else{
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.comp.open();
							this.comp.button6.setVisible(true);
						},this),cc.delayTime(0.5),func1));
					}
				}
				break;
			case TAG_ITEM_UV1800:
				cc.log("点击了UV1800");
				if(this.status==true){
					this.status=false;
					if(action==ACTION_DO1){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.uv.openuv.setVisible(true);
							this.uv.open();
						},this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO2){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.sample.open();
							this.sample.pull.setVisible(false);
						},this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO3){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.sample.open();
							this.sample.vessel1.setVisible(true);
							this.sample.uv1800.setVisible(false);
							this.sample.uv1800_1.setVisible(true);
						},this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO4){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.sample.open();
							this.sample.vessel1.setVisible(false);
							this.sample.uv1800.setVisible(false);
							this.sample.uv1800_1.setVisible(true);
						},this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO5){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.sample.open();
							this.sample.uv1800.setVisible(false);
							this.sample.uv1800_1.setVisible(true);
							this.sample.vessel.setVisible(true);
						},this),cc.delayTime(0.5),func1));
					}
				}
				break;
			case TAG_ITEM_EQUIT:
				cc.log("点击了调配工具");
				if(this.status==true){
					this.status=false;
					if(action==ACTION_NONE){
						//调配界面1
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.getChildByTag(TAG_SHOW).kill();
							this.equitment.open();
						},this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO1){
						//调配界面2
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.equitment1.open();
							this.equitment1.vessel2.setSpriteFrame("equitment/vessel1.png");
						}, this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO2){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.equitment1.open();
							this.equitment1.vessel1.setVisible(true);
							this.equitment1.vessel2.setVisible(true);
						},this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO3){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.equitment1.open();
							this.equitment1.vessel2.setSpriteFrame("equitment/vessel2.png");
							this.equitment1.line1.setVisible(false);
						}, this),cc.delayTime(0.5),func1));
					}else if(action==ACTION_DO4){
						pSender.runAction(cc.sequence(cc.callFunc(function() {
							this.equitment.open();
						},this),cc.delayTime(0.5),func1));
					}
				}
				break;
			case TAG_ITEM_PAPERITEM:
				cc.log("点击了擦拭纸");
				if(this.status==true){
					this.status=false;
					this.wipe(func,action,pSender);
				}
				break;
			case TAG_ITEM_PAPERITEM1:
				cc.log("点击了吸水纸");
				if(this.status==true){
					this.status=false;
				this.absorb(func,action,pSender);
				}
				break;
			default:
				break;
			}
	},
	wipe:function(func,action,pSender){
		this.paper.setVisible(true);
		var moveAction=new cc.MoveTo(1,cc.p(gg.c_width*1.2,gg.c_height*0.9));
		var moveAction1=new cc.MoveTo(1,cc.p(gg.c_width*1.3,gg.c_height*0.9));
		var wipeAction=new cc.MoveBy(0.5,cc.p(10,0));
		var wipeAction1=new cc.MoveBy(0.5,cc.p(-20, 0));
		var moveback=new cc.MoveTo(0.5,cc.p(gg.width*0.88,gg.height*0.945));
		var fadein=new cc.FadeIn(0.5,100);
		var fadeout=new cc.FadeOut(0.5,0);
		if(action==ACTION_DO1){
			this.paper.runAction(cc.sequence(cc.spawn(fadein,moveAction),wipeAction,
					wipeAction1,cc.spawn(moveback,fadeout),func));
		}else if(action==ACTION_DO2){
			this.paper.runAction(cc.sequence(cc.spawn(fadein,moveAction1),wipeAction,
					wipeAction1,cc.spawn(moveback,fadeout),func));
		}
	},
	fadeinLabel:function(){
		var label=new cc.LabelTTF("洗涤玻璃仪器,连接和检查仪器",gg.fontName,gg.fontSize);
		label.setColor(cc.color(0, 0, 0, 255));
		this.addChild(label);
		label.setPosition(gg.c_width, gg.c_height*1.8);
		label.runAction(cc.fadeOut(5));
	},
//	fadeinLabel1:function(){
//		var label=new cc.LabelTTF("关闭电源、填写仪器使用记录,整理台面、处理废物和废液",gg.fontName,gg.fontSize);
//		label.setColor(cc.color(0, 0, 0, 255));
//		this.addChild(label);
//		label.setPosition(gg.c_width, gg.c_height*1.8);
//		label.runAction(cc.fadeOut(5));
//	},
	absorb:function(func,action,pSender){
		this.paper1.setVisible(true);
		var moveAction=new cc.MoveTo(1,cc.p(gg.c_width*1.2,gg.c_height*0.9));
		var moveAction1=new cc.MoveTo(1,cc.p(gg.c_width*1.3,gg.c_height*0.9));
		var moveback=new cc.MoveTo(0.5,pSender.getPosition());
		var absorbAction=new cc.MoveBy(0.5,cc.p(0, 10));
		var absorbAction1=new cc.MoveBy(0.5,cc.p(0,-20));
		var fadein=new cc.FadeIn(0.5,100);
		var fadeout=new cc.FadeOut(0.5,0);
		if(action==ACTION_DO1){
			this.paper1.runAction(cc.sequence(cc.spawn(fadein,moveAction),absorbAction,absorbAction1,cc.spawn(moveback,fadeout),func));
		}else if(action==ACTION_DO2){
			this.paper1.runAction(cc.sequence(cc.spawn(fadein,moveAction1),absorbAction,absorbAction1,cc.spawn(moveback,fadeout),func));
		}
	},
	checkActionDone:function(pSender){
		var tag=pSender.getTag();
		if(tag==TAG_ITEM_PAPERITEM1){
			this.paper1.setVisible(false);
		}else if(tag==TAG_ITEM_PAPERITEM){
			this.paper.setVisible(false);
		}
		this.flow.next();
		this.status=true;
	}
});
